package cn.south.campus.admin.sys.model.vo;

import cn.south.campus.admin.sys.model.entity.SysDept;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * @author chow
 * @since 2024/10/31
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysDeptVo extends BaseVO {

    private Long parentId;

    private Integer sort;

    private String name;

    private String leader;

    private String mobile;

    private String email;

    private Integer status;
    /**
     * 子部门
     */
    private List<SysDeptVo> children;

    public static SysDeptVo convert(SysDept entity){
        SysDeptVo vo = new SysDeptVo();
        vo.setId(entity.getId());
        vo.setParentId(entity.getParentId());
        vo.setSort(entity.getSort());
        vo.setName(entity.getName());
        vo.setLeader(entity.getLeader());
        vo.setMobile(entity.getMobile());
        vo.setEmail(entity.getEmail());
        vo.setStatus(entity.getStatus());
        vo.setCreateTime(DateUtil.format(entity.getCreateTime()));
        vo.setUpdateTime(DateUtil.format(entity.getUpdateTime()));
        return vo;
    }

    public static SysDept convert(SysDeptVo vo){
        SysDept entity = new SysDept();
        entity.setId(vo.getId());
        entity.setParentId(vo.getParentId());
        entity.setSort(vo.getSort());
        entity.setName(vo.getName());
        entity.setLeader(vo.getLeader());
        entity.setMobile(vo.getMobile());
        entity.setEmail(vo.getEmail());
        entity.setStatus(vo.getStatus());
        entity.setCreateTime(DateUtil.parseString(vo.getCreateTime()));
        entity.setUpdateTime(DateUtil.parseString(vo.getUpdateTime()));
        return entity;
    }
}
